package com.shop.controller.user;

import com.shop.context.BaseContext;
import com.shop.dto.CommentsDTO;
import com.shop.entity.Comments;
import com.shop.entity.CommentsReply;
import com.shop.result.Result;
import com.shop.service.CommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;

@RestController("usercommentsController")
@RequestMapping("/user/comments")
@Api(tags = "C端-分类接口")
@Slf4j
public class CommentsController {

    @Autowired
    private CommentsService commentsService;
    /**
     * 增加评论
     * @param comments
     * @return
     */
    @ApiOperation("增加评论")
    @PostMapping("/add")
    public Result add(@RequestBody Comments comments) {
        log.info("增加评论:{}",comments);
        commentsService.save(comments);
        return Result.success();
    }

//    /**
//     * 根据商户id查询评论
//     * @param ownerId
//     * @return
//     */
//    @ApiOperation("根据商户id查询评论")
//    @GetMapping("/list/{ownerId}")
//    public Result getById(@PathVariable Long ownerId) {
//        log.info("根据id查询评论:{}",ownerId);
//        List<CommentsDTO> commentsDTO = commentsService.getById(ownerId);
//        if (commentsDTO.isEmpty()) {
//            return Result.success();
//        }
//        return Result.success(commentsDTO);
//    }

    /**
     * 查询评论
     * @param commentsDTOs
     * @return
     */
    @ApiOperation("查询评论")
    @GetMapping("/list")
    public Result list(List<CommentsDTO> commentsDTOs) {
        log.info("根据id查询评论:{}",commentsDTOs);
        commentsDTOs = commentsService.list(commentsDTOs);
        if (commentsDTOs.isEmpty()) {
            return Result.success();
        }
        return Result.success(commentsDTOs);
    }
    /**
     * 删除评论
     * @param id
     * @return
     */
    @ApiOperation("删除评论")
    @DeleteMapping("/delete")
    public Result delete(Long id) {
        log.info("删除评论:{}",id);
        commentsService.delete(id);
        return Result.success();
    }
}
